package org.loofer.uikit;

import android.content.Context;
import android.util.AttributeSet;
import com.bumptech.glide.Glide;
import com.makeramen.roundedimageview.RoundedImageView;
import org.loofer.ext.component.logger.Logger;
import org.loofer.ext.utils.StringUtils;

public class AsyncRoundImageView extends RoundedImageView {
    private static final String TAG = "AsyncRoundImageView";
    private String mUrl;

    public AsyncRoundImageView(Context context) {
        super(context);
    }

    public AsyncRoundImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AsyncRoundImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void setUrl(String url) {
        this.mUrl = url;
        loadImage();
    }

    private void loadImage() {
        try {
            if (StringUtils.isNotEmpty(this.mUrl)) {
                Glide.with(getContext()).load(this.mUrl).into(this);
            }
        } catch (Object e) {
            Logger.e(TAG, e);
        }
    }
}
